home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / sysb091a.zip / sysbench / src / pmb_gfx.c < prev    next >
Text File  |  1996-05-19  |  28KB  |  958 lines

  1.  
  2. // SysBench graphics test module
  3.  
  4. #define INCL_WIN
  5. #define INCL_GPI
  6. #define INCL_DOS
  7. #include <os2.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "pmb.h"
  11. #include "types.h"
  12.  
  13. #define ID_WINDOW1 8000
  14. #define PMB_GFX_CLASS "SysBench gfx winclass"
  15. #define WIN_WIDTH 640
  16. #define WIN_HEIGHT 460
  17. #define MIN_GFX_TIME 10.0
  18. #define MIN_MEASURE 0.1
  19. #define MARGINAL 1.1
  20. #define RUN_NUM 500
  21.  
  22. //static HAB  hab;
  23.  
  24. extern void err(char* s);
  25. extern void warn(char* s);
  26. extern void log(char* s);
  27. extern HAB anchorblock(void);
  28. extern double rtime(void);    // real time in milliseconds
  29. extern double test_time;
  30.  
  31. VOID APIENTRY paint_vlines(ULONG unused);
  32. VOID APIENTRY paint_dlines(ULONG unused);
  33. VOID APIENTRY paint_hlines(ULONG unused);
  34. VOID APIENTRY paint_bitblitss(ULONG unused);
  35. VOID APIENTRY paint_bitblitms(ULONG unused);
  36. VOID APIENTRY paint_text(ULONG unused);
  37. VOID APIENTRY paint_fillrect(ULONG unused);
  38. VOID APIENTRY paint_patrect(ULONG unused);
  39. static MRESULT EXPENTRY GfxWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  40. static void Open(void *paintfun);
  41. static void Close(void);
  42. static HWND hwndClient = NULLHANDLE;         /* Client area window handle    */
  43. static HWND hwndFrame = NULLHANDLE;          /* Frame window handle          */
  44. static HMQ  hmq;
  45. static ULONG flCreate;                       /* Window creation control flags*/
  46. static HAB bkHab;
  47. static TID paint_tid;
  48. static double result;
  49.  
  50. static void Open(void *paintfun) {
  51.   s32 w,h, x,y;
  52.   RECTL rctl, rctlScreen;
  53.   QMSG qmsg;                            /* Message from message queue   */
  54.   hwndClient = NULLHANDLE;         /* Client area window handle    */
  55.   hwndFrame = NULLHANDLE;          /* Frame window handle          */
  56. //  hab = anchorblock();
  57.  
  58.   if ((bkHab = WinInitialize(0)) == 0L) /* Initialize PM     */
  59.     err("Can't get anchor block handle for background thread");
  60.  
  61.   if ((hmq = WinCreateMsgQueue( bkHab, 0 )) == 0L)/* Create a msg queue */
  62.     err("Can't create message queue for graphics test window");
  63.  
  64.   if (!WinRegisterClass(bkHab, (PSZ)PMB_GFX_CLASS, (PFNWP)GfxWindowProc, 0, 0)) {
  65.     err("GFX test error: can't register class for child test window");
  66.   }
  67.  
  68.   flCreate = FCF_TITLEBAR | FCF_BORDER | FCF_SYSMENU;
  69.  
  70.   if ((hwndFrame = WinCreateStdWindow(
  71.                HWND_DESKTOP,            /* Desktop window is parent     */
  72.                0,                       /* window styles           */
  73.                &flCreate,               /* Frame control flag           */
  74.                PMB_GFX_CLASS,    /* Client window class name     */
  75.                "SysBench graphics test window",    /* window text               */
  76.                0,                       /* No special class style       */
  77.                (HMODULE)0L,             /* Resource is in .EXE file     */
  78.                ID_WINDOW1,               /* Frame window identifier      */
  79.                &hwndClient              /* Client window handle         */
  80.                )) == 0L)
  81.     err("Can't create graphics test window");
  82.  
  83.   WinQueryWindowRect(HWND_DESKTOP, &rctlScreen);
  84.  
  85.   rctl.xLeft = 0;
  86.   rctl.yBottom = 0;
  87.   rctl.xRight = WIN_WIDTH-1;
  88.   rctl.yTop = WIN_HEIGHT-1;
  89.   if (!WinCalcFrameRect(hwndFrame, &rctl, false))
  90.     err("Gfx test: WinCalcFrameRect() error");
  91.  
  92.   // now adjust position to make it centered on the screen
  93.   x = ((rctlScreen.xRight-rctlScreen.xLeft+1) - (rctl.xRight-rctl.xLeft+1))/2;
  94.   y = ((rctlScreen.yTop-rctlScreen.yBottom+1) - (rctl.yTop-rctl.yBottom+1))/2;
  95.  
  96.   w = rctl.xRight-rctl.xLeft+1;
  97.   h = rctl.yTop-rctl.yBottom+1;
  98.  
  99.   WinSetWindowPos( hwndFrame,      /* Shows and activates frame    */
  100.                    HWND_TOP,            /* window at position x,y  */
  101.                    x, y, w, h,         /* and size w,h     */
  102.                    SWP_SIZE | SWP_MOVE | SWP_SHOW
  103.                  );
  104.  
  105.   DosCreateThread(&paint_tid, (PFNTHREAD)paintfun, 0, 0, 64000);
  106.   while( WinGetMsg( bkHab, &qmsg, 0L, 0, 0 ) )
  107.     WinDispatchMsg( bkHab, &qmsg );
  108. }
  109.  
  110. static void Close(void) {
  111.   WinDestroyWindow(hwndFrame);           /* Tidy up...                   */
  112.   WinDestroyMsgQueue( hmq );             /* Tidy up...                   */
  113.   WinTerminate(bkHab);
  114. }
  115.  
  116. double pmb_gfx_vlines(void) {
  117.   Open((void*)paint_vlines);
  118.   Close();
  119.   return result;
  120. }
  121.  
  122. double pmb_gfx_dlines(void) {
  123.   Open((void*)paint_dlines);
  124.   Close();
  125.   return result;
  126. }
  127.  
  128. double pmb_gfx_hlines(void) {
  129.   Open((void*)paint_hlines);
  130.   Close();
  131.   return result;
  132. }
  133.  
  134. double pmb_gfx_bitblitss(void) {
  135.   Open((void*)paint_bitblitss);
  136.   Close();
  137.   return result;
  138. }
  139.  
  140. double pmb_gfx_bitblitms(void) {
  141.   Open((void*)paint_bitblitms);
  142.   Close();
  143.   return result;
  144. }
  145.  
  146. double pmb_gfx_textrender(void) {
  147.   Open((void*)paint_text);
  148.   Close();
  149.   return result;
  150. }
  151.  
  152. double pmb_gfx_fillrect(void) {
  153.   Open((void*)paint_fillrect);
  154.   Close();
  155.   return result;
  156. }
  157.  
  158. double pmb_gfx_patrect(void) {
  159.   Open((void*)paint_patrect);
  160.   Close();
  161.   return result;
  162. }
  163.  
  164. static MRESULT EXPENTRY
  165. GfxWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  166. {
  167.   switch( msg )
  168.   {
  169.     case WM_CREATE:
  170.       break;
  171.  
  172.     case WM_COMMAND:
  173.       break;
  174.  
  175.     case WM_ERASEBACKGROUND:
  176.       return (MRESULT)( FALSE ); // TRUE -> yes, erase the background
  177.  
  178.     case WM_PAINT:
  179.       {
  180.         HPS    hps;
  181.         RECTL  rc;
  182.         POINTL pt;
  183.  
  184.         hps = WinBeginPaint( hwnd, 0L, &rc );
  185.         GpiSetColor( hps, CLR_BLACK );      // colour of the text,
  186.         GpiSetBackColor( hps, CLR_BLACK );   // its background and
  187.         GpiSetBackMix( hps, BM_OVERPAINT );  // how it mixes,
  188.         GpiSetMix( hps, FM_OVERPAINT );  // how it mixes,
  189. //        WinFillRect(hps, &rc, CLR_BLACK);
  190.         WinEndPaint( hps );                  // Drawing is complete
  191.         break;
  192.       }
  193.     case WM_CLOSE:
  194.       exit(1); //WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
  195.       break;
  196.     default:
  197.       return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  198.   }
  199.   return (MRESULT)FALSE;
  200. }
  201.  
  202. VOID APIENTRY paint_vlines(ULONG unused) {
  203.   HPS hps;
  204.   POINTL p1, p2;
  205.   double t1, t2;
  206.   RECTL rc;
  207.   s32 i, j, c, runs, runs_10;
  208.  
  209.   hps = WinGetPS(hwndClient);
  210.   GpiSetBackMix( hps, BM_OVERPAINT );  // how it mixes,
  211.   GpiSetMix( hps, FM_OVERPAINT );  // how it mixes,
  212.   GpiSetColor(hps, CLR_WHITE);
  213.   GpiSetBackColor( hps, CLR_BLACK);
  214.   rc.xLeft = 0;
  215.   rc.xRight = WIN_WIDTH;
  216.   rc.yBottom = 0;
  217.   rc.yTop = WIN_HEIGHT;
  218.   WinFillRect(hps, &rc, CLR_BLACK);
  219.  
  220.   DosSleep(200);
  221.  
  222.   p1.x = WIN_WIDTH/2;
  223.   p1.y = 1;
  224.   p2.x = WIN_WIDTH/2;
  225.   p2.y = WIN_HEIGHT-2;
  226.   GpiMove(hps, &p1);
  227.   runs = RUN_NUM;
  228.   runs_10 = runs/10;
  229.   while(1) {
  230.     j = 0;
  231.     c = 0;
  232.     t1 = rtime();
  233.     for(i = 0; i < runs; i++) {
  234.       GpiLine(hps, &p2);
  235.       GpiLine(hps, &p1);
  236.       if (j++ == runs_10) {
  237.         GpiSetColor(hps, (c++)%6+1);
  238.         j = 0;
  239.       }
  240.     }
  241.     t2 = rtime();
  242.     test_time = (t2-t1);
  243.  
  244.     if (test_time < MIN_GFX_TIME)   /* if total time in test < min time */
  245.        {
  246.         if ((test_time) < MIN_MEASURE)  /* if total time in test < 0.1 */
  247.            {
  248.             runs = MIN_GFX_TIME/MIN_MEASURE*runs; /* increase number of runs by factor 100 */
  249.             runs_10 = runs/10;
  250.             }
  251.         else                         /* if 10 > total time in test > 0.1 */
  252.            {
  253.             runs = MIN_GFX_TIME*MARGINAL/(test_time)*runs; /* increase runs by enough to make tottime > 10 */
  254.             runs_10 = runs/10;
  255.             }
  256.         }
  257.     else                              /* if total time in test > 10 */
  258.      {
  259.       break;                          /* stop test */
  260.       }                               /* otherwise repeat with new run # */
  261.   }
  262.  
  263.   result = runs*2.0/(test_time)*(WIN_HEIGHT-2);
  264.   WinReleasePS(hps);
  265.   WinPostMsg( hwndClient, WM_QUIT, (MPARAM)0,(MPARAM)0 );
  266. }
  267.  
  268. VOID APIENTRY paint_hlines(ULONG unused) {
  269.   HPS hps;
  270.   POINTL p1, p2;
  271.   RECTL rc;
  272.   double t1, t2;
  273.   s32 i, j, c, runs, runs_10;
  274.  
  275.   hps = WinGetPS(hwndClient);
  276.   GpiSetBackMix( hps, BM_OVERPAINT );  // how it mixes,
  277.   GpiSetMix( hps, FM_OV